-
Notifications
You must be signed in to change notification settings - Fork 0
Automated Test: plugins/rename-instrumentation-middleware-to-metrics-middleware #337
Automated Test: plugins/rename-instrumentation-middleware-to-metrics-middleware #337
Conversation
…are (#76186) * Plugins: Chore: Renamed instrumentation middleware to metrics middleware * Removed repeated logger attributes in middleware and contextual logger * renamed loggerParams to logParams * PR review suggestion * Add contextual logger middleware * Removed unused params from logRequest * Removed unwanted changes * Safer FromContext method * Removed traceID from logParams
📝 WalkthroughWalkthroughThe changes add a Changes
Sequence DiagramsequenceDiagram
participant Client as Plugin Client
participant CLM as ContextualLoggerMiddleware
participant LM as LoggerMiddleware
participant MM as MetricsMiddleware
participant Backend as Backend Plugin
Client->>CLM: QueryData(ctx, req)
CLM->>CLM: Enrich context with attributes<br/>(endpoint, pluginId, dsName, etc.)
CLM->>LM: QueryData(ctx, req)
LM->>LM: Log context-aware details<br/>using FromContext(ctx).Info()
LM->>MM: QueryData(ctx, req)
MM->>MM: Instrument metrics<br/>(request size, duration)
MM->>Backend: QueryData(ctx, req)
Backend-->>MM: response/error
MM-->>LM: response/error
LM-->>CLM: response/error
CLM-->>Client: response/error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/plugins/log/fake.go (1)
3-48:⚠️ Potential issue | 🟡 MinorKeep TestLogger log capture when using FromContext.
Returning a fresh TestLogger means logs emitted via FromContext won't be visible on the original instance, which can break assertions on captured logs. Consider returning the same logger (or sharing log storage).🔧 Suggested adjustment
-func (f *TestLogger) FromContext(_ context.Context) Logger { - return NewTestLogger() -} +func (f *TestLogger) FromContext(_ context.Context) Logger { + return f +}
🤖 Fix all issues with AI agents
In
`@pkg/services/pluginsintegration/clientmiddleware/contextual_logger_middleware.go`:
- Around line 26-36: The middleware currently attaches user identifiers to logs
by adding pCtx.User.Login as "uname" in instrumentContext; remove or gate this
PII: delete the uname entry (remove the pCtx.User.Login append) or wrap it
behind an explicit privacy flag/anonymization check (e.g., only append a
pseudonymized user id or when a config like allowLogUsernames is true) before
calling log.WithContextualAttributes, ensuring instrumentContext and the usage
of pCtx.User.Login are the only places changed.
| // instrumentContext adds a contextual logger with plugin and request details to the given context. | ||
| func instrumentContext(ctx context.Context, endpoint string, pCtx backend.PluginContext) context.Context { | ||
| p := []any{"endpoint", endpoint, "pluginId", pCtx.PluginID} | ||
| if pCtx.DataSourceInstanceSettings != nil { | ||
| p = append(p, "dsName", pCtx.DataSourceInstanceSettings.Name) | ||
| p = append(p, "dsUID", pCtx.DataSourceInstanceSettings.UID) | ||
| } | ||
| if pCtx.User != nil { | ||
| p = append(p, "uname", pCtx.User.Login) | ||
| } | ||
| return log.WithContextualAttributes(ctx, p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid logging user identifiers by default.
Line 33–35 adds uname from pCtx.User.Login; that’s PII and can violate privacy/retention policies. Prefer removing it or gating behind explicit config/anonymization.
🔧 Proposed fix (remove username from context)
func instrumentContext(ctx context.Context, endpoint string, pCtx backend.PluginContext) context.Context {
p := []any{"endpoint", endpoint, "pluginId", pCtx.PluginID}
if pCtx.DataSourceInstanceSettings != nil {
p = append(p, "dsName", pCtx.DataSourceInstanceSettings.Name)
p = append(p, "dsUID", pCtx.DataSourceInstanceSettings.UID)
}
- if pCtx.User != nil {
- p = append(p, "uname", pCtx.User.Login)
- }
return log.WithContextualAttributes(ctx, p)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // instrumentContext adds a contextual logger with plugin and request details to the given context. | |
| func instrumentContext(ctx context.Context, endpoint string, pCtx backend.PluginContext) context.Context { | |
| p := []any{"endpoint", endpoint, "pluginId", pCtx.PluginID} | |
| if pCtx.DataSourceInstanceSettings != nil { | |
| p = append(p, "dsName", pCtx.DataSourceInstanceSettings.Name) | |
| p = append(p, "dsUID", pCtx.DataSourceInstanceSettings.UID) | |
| } | |
| if pCtx.User != nil { | |
| p = append(p, "uname", pCtx.User.Login) | |
| } | |
| return log.WithContextualAttributes(ctx, p) | |
| // instrumentContext adds a contextual logger with plugin and request details to the given context. | |
| func instrumentContext(ctx context.Context, endpoint string, pCtx backend.PluginContext) context.Context { | |
| p := []any{"endpoint", endpoint, "pluginId", pCtx.PluginID} | |
| if pCtx.DataSourceInstanceSettings != nil { | |
| p = append(p, "dsName", pCtx.DataSourceInstanceSettings.Name) | |
| p = append(p, "dsUID", pCtx.DataSourceInstanceSettings.UID) | |
| } | |
| return log.WithContextualAttributes(ctx, p) | |
| } |
🤖 Prompt for AI Agents
In
`@pkg/services/pluginsintegration/clientmiddleware/contextual_logger_middleware.go`
around lines 26 - 36, The middleware currently attaches user identifiers to logs
by adding pCtx.User.Login as "uname" in instrumentContext; remove or gate this
PII: delete the uname entry (remove the pCtx.User.Login append) or wrap it
behind an explicit privacy flag/anonymization check (e.g., only append a
pseudonymized user id or when a config like allowLogUsernames is true) before
calling log.WithContextualAttributes, ensuring instrumentContext and the usage
of pCtx.User.Login are the only places changed.
This pull request was automatically created by
@coderabbitai/e2e-reviewer.Batch created pull request.
Summary by CodeRabbit